
<template>
  <div id="app" class="login-container">
<!--    {{this.user}}-->
    <div class="aaa">
      <el-upload
          class="avatar-uploader"
          action="http://localhost:9009/user/tp"
          name="file"
          v-model="ruleForm.photo"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload">
        <img width="50px" v-if="imageUrl" :src="imageUrl" class="avatar">
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>
<!--      <img :src="ruleForm.photo" alt="" width="200px" height="200px">-->
    </div>

    <div class="bbb">
      <el-form :model="ruleForm" ref="ruleForm" label-width="80px" class="demo-ruleForm" inline >
        <el-form-item label="名称:" prop="name" >
          <el-input v-model="ruleForm.yhname" placeholder="请输入" label-width="80px"></el-input>
        </el-form-item>
        <br>

        <el-form-item label="姓名:" prop="name" >
          <el-input v-model="ruleForm.name" placeholder="请输入" label-width="80px"></el-input>
        </el-form-item>
        <br>

        <el-form-item label="手机号:" prop="name" >
          <el-input v-model="ruleForm.phone" placeholder="请输入" label-width="80px"></el-input>
        </el-form-item>
        <br>

<!--        <el-form-item label="部门:" prop="name" >-->
<!--          <el-input v-model="ruleForm.department" placeholder="请输入" label-width="80px"></el-input>-->
<!--        </el-form-item>-->
<!--        <br>-->

<!--        <el-form-item label="角色:" prop="name" >-->
<!--          <el-input v-model="ruleForm.role" placeholder="请输入" label-width="80px"></el-input>-->
<!--        </el-form-item>-->
<!--        <br>-->

        <el-form-item label="登录用户:" prop="name" >
          <el-input v-model="ruleForm.username" placeholder="请输入" label-width="80px"></el-input>
        </el-form-item>
        <br>
      </el-form>
    </div>


  </div>
</template>

<style scoped>
.aaa{
  float: right;
}
.bbb{
  float: left;
}





.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>

<script>
export default {
  data() {
    return {
      user:{},
      imageUrl:"",
      ruleForm:{},
    };
  },
  methods: {



    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 2;
      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    },

    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
      this.ruleForm.photo=res;
    },

    toUpdate(){

      //修改回显数据方法
      // var id = this.user.id;
      // this.axios.get(`http://localhost:9009/user/findById?id=${id}`).then(res=>{
      //   this.user=res.data.data;
      //   this.imageUrl=res.data.data.photo;
      // })
    },





  },
  created() {
    this.user=JSON.parse(sessionStorage.getItem('userDB'));
    this.ruleForm=this.user;
    this.imageUrl=this.ruleForm.photo;
    this.toUpdate();
  }
};
</script>
